package hibernate;

import java.util.ArrayList;

import org.hibernate.Session;

import metier.Region;
import dao.DAORegion;

public class DAORegionHBM extends DAOHibernate implements DAORegion {

	@SuppressWarnings("unchecked")
	@Override
	public ArrayList<Region> loadAll() throws Exception {
		ArrayList<Region>	tab = null;
		Session session = connect();
		
		tab = (ArrayList<Region>) session.createQuery("FROM region").list();
		
		close(session);
		return tab;
	}

	@Override
	public Region get(int id) throws Exception {
		Region r = null;
		Session	session = connect();
		
		r = (Region) session.get(Region.class, id);
		
		close(session);
		return r;
	}

	@Override
	public void save(Region region) throws Exception {
			Session	session = connect();
		
		session.save(region);
		
		close(session);		

	}

	@Override
	public void delete(Region region) throws Exception {
		Session	session = connect();
		
		session.delete(region);
		region.setIdRegion(-1);
		
		close(session);

	}

	@Override
	public void update(Region region) throws Exception {
		// TODO Auto-generated method stub

	}

}
